package Class.Basis.ComplexClass;

import java.util.Scanner;

public class Test {
    public static boolean judgeContain(ComplexClass[] arr, String id) {
        for (int i = 0; i < arr.length; i++) {
            ComplexClass cc = arr[i];
            if (id.equals(cc.getId())) {
                return true;
            }
        }
        return false;
    }

    public static int memberNum(ComplexClass[] arr) {
        int num = 0;
        for (int i = 0; i < arr.length; i++) {
            ComplexClass cc = arr[i];
            if (cc != null)
                num++;
        }
        return num;
    }

    public static void deleInfo(ComplexClass[] arr, String deleId){
        for (int i = 0; i < arr.length; i++) {
            ComplexClass cc = arr[i];
            if(cc != null)
                if(deleId.equals(cc.getId()))
                    arr[i] = null;
        }
    }

    public static ComplexClass[] expendArr(ComplexClass[] arr, ComplexClass ccNew) {
        ComplexClass[] arrNew = new ComplexClass[arr.length + 1];
        for (int i = 0; i < arr.length; i++) {
            arrNew[i] = arr[i];
        }
        arrNew[arr.length] = ccNew;
        arr = null;
        return arrNew;
    }

    public static void printInfo(ComplexClass[] arr){
        for (int i = 0; i < arr.length; i++) {
            ComplexClass cc = arr[i];
            if(cc != null)
                System.out.println(cc.toString());
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        ComplexClass cc1 = new ComplexClass("heima001", "nick", 18);
        ComplexClass cc2 = new ComplexClass("heima002", "jack", 20);
        ComplexClass cc3 = new ComplexClass("heima003", "mark", 19);

        ComplexClass[] arr1 = new ComplexClass[3];

        arr1[0] = cc1;
        arr1[1] = cc2;
        arr1[2] = cc3;

        ComplexClass ccNew = new ComplexClass(sc.nextLine(), sc.nextLine(), sc.nextInt());

        if (!judgeContain(arr1, ccNew.getId()))
            arr1 = expendArr(arr1, ccNew);
        else
            System.out.println("The id is in the list!");

        printInfo(arr1);

        System.out.println();

        deleInfo(arr1, "heima001");

        printInfo(arr1);
    }
}
